package com.oig.sys.workflow.dao;

import com.oig.sys.workflow.entity.TbAutoRule;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @author wuxl
 */
public interface ITbAutoRuleDao extends JpaRepository<TbAutoRule, Integer>, JpaSpecificationExecutor<TbAutoRule> {

	TbAutoRule getTbAutoRuleById(Integer id);


	@Query("from TbAutoRule r where r.status='04' and r.enable='1'" +
			" and r.listenerTableName=:listenerTableName and r.listenerEventOperation=:listenerEventOperation")
	List<TbAutoRule> findAllEnableRule(@Param("listenerTableName") String listenerTableName, @Param("listenerEventOperation") String listenerEventOperation);

	@Query("select r.id from TbAutoRule r where r.listenerObjectId=:objectId and r.status=:status")
	List<Integer> findIdByListenerObjectId(@Param("objectId") Integer objectId, @Param("status") String status);

	@Query("select r.id from TbAutoRule r where r.listenerObjectId=:objectId")
	List<Integer> findIdByListenerObjectId(@Param("objectId") Integer objectId);


	@Query("select r.id from TbAutoRule r where r.listenerEventId in(:eventIdList)")
	List<Integer> findIdByEventIdList(@Param("eventIdList") List<Integer> eventIdList);
}
